package com.wwg.threadSort;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: wwg
 * @date: 2022/3/11 17:15
 */


/**
 * ExecutorService线程池控制线程顺序执行
 */
public class ThreadSortPool {

    static ExecutorService executorService = Executors.newSingleThreadExecutor();

    public static void main(String[] args) throws Exception {

        final Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "执行1");
            }
        },"t1");

        final Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "执行2");
            }
        },"t2");

        Thread thread3 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "执行3");
            }
        },"t3");

        executorService.submit(thread1);
        executorService.submit(thread2);
        executorService.submit(thread3);
        executorService.shutdown();
    }
}
